package com.gaofeng.day19;

import java.util.*;

public class demo04 {
    public static void main(String[] args) {
        String[] arr = {"A","B","C","D"};

        ArrayList<String> list = new ArrayList<>();
        Random r = new Random();

        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(arr.length);
            list.add(arr[index]);
        }

        System.out.println(list);

        HashMap<String,Integer> hm = new HashMap<>();
        for (String s : list) {
            if(hm.containsKey(s)){
                hm.put(s,hm.get(s)+1);
            }else{
                hm.put(s,1);
            }
        }
        hm.entrySet().forEach(s -> {
            System.out.println(s);
        });

        // 求最大值
        int max = hm.get("A");
        Set<Map.Entry<String, Integer>> entries = hm.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            Integer count = entry.getValue();
            System.out.println(count);
            if(count > max){
                max = count;
            }
        }
        System.out.println(max);
        for (Map.Entry<String, Integer> entry : entries) {
            Integer count = entry.getValue();
            if(count == max){
                System.out.println(entry);
            }
        }




    }
}
